﻿#ifndef INTERCOM_H
#define INTERCOM_H

#include <QObject>
#include <QTcpServer>
#include <QTcpSocket>
#include <QMap>
#include "oeasycommon.h"
#include "configfile.h"
#include "commonfuc.h"
#include <QTimer>
#include <QMutex>

class Intercom : public QObject
{
    Q_OBJECT
public:
    explicit Intercom(int port, QObject *parent = 0);
    ~Intercom();
    void listen();
private:
    QTcpServer *m_server;
    QMap<QTcpSocket *, QString> m_cliMap;
    unsigned short m_listenPort;
    QMap<QTcpSocket *, QTimer*> m_getMacTimerMap;
    QMutex m_timerMutex;
    QMap<QString, QByteArray> m_faceImgMap;
signals:
    void textRecv(QString);
    void sigOpenDoor(QByteArray);
public slots:
    void onNewConnection();
    void onAcceptError(QAbstractSocket::SocketError);
    void onClose(QAbstractSocket::SocketError);
    void onRead();
    void onFaceOpenDoor(QString mac, QString userid, QByteArray jpg);
    void onGetMacTimeout();
};

#endif // INTERCOM_H
